//
//  FeedBackViewController.m
//  Grammar
//
//  Created by Rick on 7/28/13.
//
//

#import "FeedBackViewController.h"
#import "FeedBackDataRequest.h"

#define FEEDBACK_DATA_REQUEST   @"FEEDBACK_DATA_REQUEST"

@interface FeedBackViewController ()

@end

@implementation FeedBackViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [_feedTextView becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:FEEDBACK_DATA_REQUEST object:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)tapBackButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)tapCommitButton:(id)sender {
    if (![_feedTextView.text isEqualToString:@""]) {
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        [parameters setObject:_feedTextView.text forKey:@"content"];

        [FeedBackDataRequest requestWithParameters:parameters withIndicatorView:nil withCancelSubject:FEEDBACK_DATA_REQUEST onRequestStart:nil onRequestFinished:^(ITTBaseDataRequest *request) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:[request.resultDic objectForKey:@"msg"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alertView show];
            [alertView release];
            _feedTextView.text = @"";
            [self performSelector:@selector(tapBackButton:)];
        } onRequestCanceled:^(ITTBaseDataRequest *request) {
            
        } onRequestFailed:^(ITTBaseDataRequest *request) {
            
        }];
    }else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"意见反馈内容不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertView show];
        [alertView release];
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if ([textView.text isEqualToString:@""]) {
        _hintLabel.hidden = NO;
    }else {
        _hintLabel.hidden = YES;
    }
}

- (void)dealloc {
    [_hintLabel release];
    [_feedTextView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setHintLabel:nil];
    [self setFeedTextView:nil];
    [super viewDidUnload];
}
@end
